package gameoflife;
 
public enum Heading {
	N(0, -1),
	NE(1, -1),
	E(1, 0),
	SE(1, 1),
	S(0, 1),
	SW(-1, 1),
	W(-1, 0),
	NW(-1, -1);

	public final int x, y;

	public static final Heading[] ALL = Heading.values();

	Heading(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public final Position toPosition(Position position) {
		return new Position(position.x + x, position.y + y);
	}

	// Avoid instantiation to gain performance.
	public final Position toPosition(Position from, Position to) {
		to.x = from.x + x;
		to.y = from.y + y;
		return to;
	}

}
